package com.cloudlead.common.worker.security.internal;

import com.cloudlead.common.lang.security.Subject;
import com.cloudlead.common.worker.security.TokenInfoService;
import com.cloudlead.utils.cache.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by dean on 2015/8/19.
 */
@Service
public class SimpleTokenInfoService implements TokenInfoService {

    @Autowired(required = false)
    private CacheService cacheService;

    @Override
    public Subject getSubjectByAccessToken(String accessToken) {
        if (null != cacheService) {
            return (Subject) cacheService.get(ACCESS_TOKEN_CACHE + accessToken);
        }
        return null;
    }

    @Override
    public String getAccessTokenByUser(String username) {
        if (null != cacheService) {
            return (String) cacheService.get(USERNAME_ACCESS_TOKEN_CACHE + username);
        }
        return null;
    }
}
